/**
 * 
 */
package com.jm.web.builder;

import java.io.IOException;
import java.util.Map;

import com.jm.utils.StringBuilderEx;
import com.jm.utils.StringHelper;
import com.jm.utils.Utils;

/**
 * @author yanjie
 *
 */
public class MenuBuilder extends BaseBuilder{
	@Override
	public void RenderEnd() {
		StringBuilderEx sb = new StringBuilderEx();
		sb.Append("<div id=\"%1$s\" style=\"display:none;\">%2$s</div>",
				this.getBaseTag().getId(),
				Utils.MapToMenuHtml((Map)this.getBaseTag().GetExtValue("menuData"),null));
		
//		sb.Reset();
		
		sb.Append("\r\n<script>");
		sb.Append("$P.menus['%1$s']=new $P.menu(new Menu(null,",this.getBaseTag().getId());
		sb.Append("{content:$('div[id=%1$s]').html()",this.getBaseTag().getId());
		sb.Append(",flyOut: true");
		sb.Append(",id: '%1$s'",this.getBaseTag().getId());
		if(!StringHelper.IsNullOrEmpty(this.getBaseTag().GetExtValue("menuWidth", "")))
			sb.Append(",width:'%1$s'",this.getBaseTag().GetExtValue("menuWidth", ""));
		sb.Append("}));");	
		sb.Append("</script>");
		
		try {
			this.getOut().write(sb.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
}
